class Fishes extends egret.DisplayObjectContainer {
    public constructor() {
        super();
        this.init();
    }

    private init(): void {
        this.num =  Math.floor(Math.random()* 5 +1);
        var txtr: egret.Texture = RES.getRes("fishes"+this.num+".fish1");
        this.img = new egret.Bitmap(txtr);
        this.addChild(this.img);
        this.addEventListener(egret.Event.ENTER_FRAME, this.onEnterFrame, this);
    }

    private onEnterFrame(): void {
        if (this.slowNum++ % this.slow != 0) {
            return;
        }
        this.x -= 10;
        if(this.x <-180){
            this.x = 600;
        }
        let num = Math.floor(Math.random()* 10 +1);
        let newTexture = RES.getRes("fishes"+this.num+".fish" + num);
        this.img.texture = newTexture;
    }

    private img: egret.Bitmap;
    private slow: number = 7;
    private slowNum: number = 0;
    private num: number = 0;
}